package com.weetop.aklyscan.activity.sreach;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.classic.adapter.BaseAdapterHelper;
import com.classic.adapter.CommonRecyclerAdapter;
import com.weetop.aklyscan.R;
import com.weetop.aklyscan.base.BaseActivity;
import com.weetop.aklyscan.base.mvp.BaseModel;
import com.weetop.aklyscan.bean.SerailBean1;
import com.weetop.aklyscan.presenter.RecordPresent;
import com.weetop.aklyscan.view.RecordView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SearchPositionDetailActivity7 extends BaseActivity<RecordPresent> implements RecordView, CommonRecyclerAdapter.OnItemClickListener {
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.txt_title)
    TextView txt_title;
    @BindView(R.id.tv_ck_time)
    TextView form1View;
    @BindView(R.id.tv_ck_num)
    TextView form2View;
    @BindView(R.id.tv_order_sn)
    TextView form3View;
    @BindView(R.id.tv_member_sn)
    TextView form4View;
    private CommonRecyclerAdapter<SerailBean1.DataBean> adapter;
    private List<SerailBean1.DataBean> list = new ArrayList<>();

    @Override
    protected RecordPresent createPresenter() {
        return new RecordPresent(this, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_search_position_detail_7);
        ButterKnife.bind(this);
        String order_sn = getIntent().getStringExtra("order_sn");
        String keywords = getIntent().getStringExtra("keywords");
        String type = getIntent().getStringExtra("type");
        String type_two = getIntent().getStringExtra("type_two");
        String type_two_status = getIntent().getStringExtra("type_two_status");
        String goods_model = getIntent().getStringExtra("goods_model");
        String order_id = getIntent().getStringExtra("order_id");
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        adapter = new CommonRecyclerAdapter<SerailBean1.DataBean>(mActivity, R.layout.item_search_position_detail_7, list) {
            @Override
            public void onUpdate(BaseAdapterHelper helper, SerailBean1.DataBean item, int position) {
                helper.setText(R.id.tv_xuhao, position + 1 + "");
                if(type_two_status.equals("2")){
                    helper.setText(R.id.tv_time, item.getSerial_code());
                }else{
                    helper.setText(R.id.tv_time, item.getCode());
                }
                helper.setText(R.id.tv_num, item.getGoods_model());
                helper.setText(R.id.tv_number, item.getCreate_time());
                helper.setText(R.id.tv_member_number, item.getUpdate_time());
            }
        };
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);
        if(type_two_status.equals("2")){
            mPresenter.wfh(goods_model, order_id);
        }else{
            mPresenter.Into57("2", type_two, type_two_status, order_sn, keywords);
        }

    }

    @Override
    public void getInto57Success(BaseModel<SerailBean1> o) {
        List<SerailBean1.DataBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
    }

    @Override
    public void serail12Success(BaseModel<SerailBean1> o) {
        List<SerailBean1.DataBean> listBeans = o.getData().getList_data();
        list.clear();
        adapter.clear();
        list.addAll(listBeans);
        adapter.addAll(listBeans);
    }

    @OnClick(R.id.iv_back)
    public void onViewClicked() {
        finish();
    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int i) {

    }
}
